home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / Documentary Synchronicity ƒ / Source ƒ / Support ƒ / ZoomWindowToTrash.c < prev   
Encoding:
C/C++ Source or Header  |  1995-06-10  |  4.9 KB  |  192 lines  |  [TEXT/KAHL]

  1. /* 4567890123456789012345678901234567890123456789012345678901234567 */
  2. #include <Windows.h>
  3. #include <LowMem.h>
  4. #include <Folders.h>
  5. #include <Errors.h>
  6.  
  7. #if STRICT_WINDOWS
  8. OSErr ZoomWindowToTrash(WindowRef aWindow);
  9. void GetWindowRect(WindowRef aWindow, Rect *aRect);
  10. #else
  11. OSErr ZoomWindowToTrash(WindowPtr aWindow);
  12. void GetWindowRect(WindowPtr aWindow, Rect *aRect);
  13. #endif
  14. void UpdateDesktop(void);
  15. OSErr GetTrashIconRect(Rect *aRect);
  16. OSErr OpenGrayRgnPort(GrafPtr *aGrayRgnPort, 
  17.     GrafPtr *aCurrentPort, RgnHandle *aClip);
  18. void ZoomBetweenRects(Rect *aStartingRect, Rect *anEndingRect, 
  19.     short aCount);
  20. void CloseGrayRgnPort(GrafPtr aGrayRgnPort, 
  21.     GrafPtr aCurrentPort, RgnHandle aClip);
  22.         
  23. #define kNumBetween 20
  24. #define kCountDelay 1
  25.  
  26. #if STRICT_WINDOWS
  27. OSErr ZoomWindowToTrash(WindowRef aWindow) {
  28. #else
  29. OSErr ZoomWindowToTrash(WindowPtr aWindow) {
  30. #endif
  31.     OSErr theError = noErr;
  32.     Rect theStartingRect, theEndingRect;
  33.     GrafPtr theCurrentPort, theGrayRgnPort;
  34.     RgnHandle theCurrentClip;
  35.     
  36.     HideWindow(aWindow);
  37.     UpdateDesktop();
  38.     GetPort(&theCurrentPort);
  39. #if STRICT_WINDOWS
  40.     SetPortWindowPort(aWindow);
  41. #else
  42.     SetPort(aWindow);
  43. #endif
  44.     GetWindowRect(aWindow, &theStartingRect);
  45.     theError = GetTrashIconRect(&theEndingRect);
  46.     if (theError == noErr) {
  47.         SetPort(theCurrentPort);
  48.         theError = OpenGrayRgnPort(&theGrayRgnPort, &theCurrentPort, 
  49.             &theCurrentClip);
  50.     }
  51.     if (theError == noErr) {
  52.         ZoomBetweenRects(&theStartingRect, &theEndingRect, 
  53.             kNumBetween);
  54.         CloseGrayRgnPort(theGrayRgnPort, theCurrentPort, 
  55.             theCurrentClip);    
  56.     }
  57.     return theError;
  58. }
  59.  
  60. void UpdateDesktop(void) {
  61.     EventRecord theEvent;
  62.     (void)WaitNextEvent(0, &theEvent, 10, nil);
  63. }
  64.  
  65. #if STRICT_WINDOWS
  66. void GetWindowRect(WindowRef aWindow, Rect *aRect) {
  67. #else
  68. void GetWindowRect(WindowPtr aWindow, Rect *aRect) {
  69. #endif
  70.     GrafPtr theCurrentPort;
  71.     Point thePoint;
  72.     
  73.     GetPort(&theCurrentPort);
  74. #if STRICT_WINDOWS
  75.     SetPortWindowPort(aWindow);
  76.     thePoint.v = GetWindowPort(aWindow)->portRect.top;
  77.     thePoint.h = GetWindowPort(aWindow)->portRect.left;
  78. #else
  79.     SetPort(aWindow);
  80.     thePoint.v = aWindow->portRect.top;
  81.     thePoint.h = aWindow->portRect.left;
  82. #endif
  83.     LocalToGlobal(&thePoint);
  84.     (*aRect).top = thePoint.v;
  85.     (*aRect).left = thePoint.h;
  86. #if STRICT_WINDOWS
  87.     thePoint.v = GetWindowPort(aWindow)->portRect.bottom;
  88.     thePoint.h = GetWindowPort(aWindow)->portRect.right;
  89. #else
  90.     thePoint.v = aWindow->portRect.bottom;
  91.     thePoint.h = aWindow->portRect.right;
  92. #endif
  93.     LocalToGlobal(&thePoint);
  94.     (*aRect).bottom = thePoint.v;
  95.     (*aRect).right = thePoint.h;
  96.     SetPort(theCurrentPort);
  97. }
  98.  
  99. OSErr GetTrashIconRect(Rect *aRect) {
  100.     OSErr theError;
  101.     short theVRefNum;
  102.     long theDirID;
  103.     Str255 theName;
  104.     CInfoPBRec pb;
  105.     Point thePoint;
  106.     
  107.     theError = FindFolder(kOnSystemDisk, kTrashFolderType, 
  108.         kDontCreateFolder, &theVRefNum, &theDirID);
  109.     if (theError == fnfErr) {
  110.         theError = FindFolder(kOnSystemDisk, 
  111.             kWhereToEmptyTrashFolderType, kDontCreateFolder,
  112.             &theVRefNum, &theDirID);
  113.     }
  114.     if (theError == noErr) {
  115.         pb.dirInfo.ioNamePtr = theName;
  116.         pb.dirInfo.ioVRefNum = theVRefNum;
  117.         pb.dirInfo.ioDrDirID = theDirID;
  118.         pb.dirInfo.ioFDirIndex = -1;    /* use ioDrDirID */
  119.         theError = PBGetCatInfoSync(&pb);
  120.         if (theError == noErr) {
  121.             thePoint.v = pb.dirInfo.ioDrUsrWds.frLocation.v;
  122.             thePoint.h = pb.dirInfo.ioDrUsrWds.frLocation.h;
  123.             LocalToGlobal(&thePoint);
  124.             aRect->top = thePoint.v;
  125.             aRect->left = thePoint.h;
  126.             aRect->bottom = aRect->top + 32;
  127.             aRect->right = aRect->left + 32;
  128.         }
  129.     }
  130.     return theError;
  131. }
  132.  
  133. OSErr OpenGrayRgnPort(GrafPtr *aGrayRgnPort, GrafPtr *aCurrentPort, 
  134.         RgnHandle *aClip) {
  135.     OSErr theError = noErr;
  136.     RgnHandle theGrayRgn = LMGetGrayRgn();
  137.  
  138.     GetPort(aCurrentPort);
  139.     *aGrayRgnPort = (GrafPtr)NewPtrClear(sizeof(GrafPort));
  140.     if (*aGrayRgnPort != nil) {
  141.         OpenPort(*aGrayRgnPort);
  142.         CopyRgn(theGrayRgn, (*aGrayRgnPort)->visRgn);
  143.         theError = MemError();
  144.         if (theError == noErr) {
  145.             (*aGrayRgnPort)->portRect = (**theGrayRgn).rgnBBox;
  146.             *aClip = NewRgn();
  147.             if (*aClip != nil) {
  148.                 GetClip(*aClip);
  149.             } else {
  150.                 theError = MemError();
  151.             }
  152.         }
  153.     } else {
  154.         theError = MemError();
  155.     }
  156.     return theError;
  157. }
  158.  
  159. void CloseGrayRgnPort(GrafPtr aGrayRgnPort, GrafPtr aCurrentPort, 
  160.         RgnHandle aClip) {
  161.     SetClip(aClip);
  162.     DisposeRgn(aClip);
  163.     ClosePort(aGrayRgnPort);
  164.     SetPort(aCurrentPort);
  165. }
  166.  
  167. void ZoomBetweenRects(Rect *aStartingRect, Rect *anEndingRect, 
  168.         short aCount) {
  169.     short top, left, bottom, right, count;
  170.     Rect theRect = *aStartingRect;
  171.     long theTicks;
  172.  
  173.     PenPat(&qd.gray);
  174.     PenMode(patXor);
  175.     top = (anEndingRect->top - aStartingRect->top) / (aCount + 1);
  176.     left = (anEndingRect->left - aStartingRect->left) / (aCount + 1);
  177.     bottom = 
  178.         (anEndingRect->bottom - aStartingRect->bottom) / (aCount + 1);
  179.     right = 
  180.         (anEndingRect->right - aStartingRect->right) / (aCount + 1);
  181.     
  182.     for (count=0; count<(aCount+2); count ++) {
  183.         FrameRect(&theRect);
  184.         Delay(kCountDelay, &theTicks);
  185.         FrameRect(&theRect);
  186.         theRect.top += top;
  187.         theRect.left += left;
  188.         theRect.bottom += bottom;
  189.         theRect.right += right;
  190.     }
  191. }
  192.